package com.zx.zxapibackend.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zx.zxapibackend.service.UserInterfaceInfoService;
import com.zx.zxapicommon.model.entity.UserInterfaceInfo;
import com.zx.zxapicommon.service.InnerUserInterfaceInfoService;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * @author 张旭
 * @version 1.0
 */
@DubboService
public class InnerUserInterfaceInfoServiceImpl implements InnerUserInterfaceInfoService {
    @Resource
    private UserInterfaceInfoService userInterfaceInfoService;

    //模拟调用，扣减次数
    @Override
    public boolean invokeCount(long interfaceId, long userId) {
        return userInterfaceInfoService.invokeCount(interfaceId, userId);
    }

    //检查用户是否还有调用权限
    @Override
    public boolean checkUserInvokeCount(Long userId, String interfaceId) {
        QueryWrapper<UserInterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        queryWrapper.eq("interfaceInfoId",interfaceId);
        UserInterfaceInfo one = userInterfaceInfoService.getOne(queryWrapper);
        if(null==one){
            return false;
        }
        return one.getLeftNum() > 0;
    }
}
